import time,unittest
import logging
from selenium import webdriver
from ddt import ddt,data,unpack
from selenium.webdriver.common.by import By
from Zsd.Excelqd import excel
filepath=r'C:\Users\15220\Desktop\数据驱动.xlsx'
sheetname='Login'
dy=excel(filepath,sheetname)
from ddt import ddt,data,unpack


@ddt
class A3mall1(unittest.TestCase):
    # TestFixture 测试固件
    def setUp(self) -> None:
        Tools().Log4()
        self.driver=webdriver.Edge()
        self.driver.maximize_window()
        self.driver.get('http://10.59.9.14:7003/')

    def tearDown(self) -> None:
        time.sleep(3)
        self.driver.quit()


    # TestCase 测试用例
    @data(*dy.getdatafromexcel())
    @unpack
    # 'caseid', 'casemk', 'casestpe', 'casevalue1', 'casevalue2']
    def test_A3mall_login(self,caseid,casemk,casestpe,casevalue1,casevalue2,caseyxj):
        logging.info('start case')
        print(caseid + '***---***' + casemk + '***---***' )
        print(casestpe)
        # 登录
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
        time.sleep(3)
        # 断言1：断言文本：会员登陆
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[4]/div/div[1]/div[1]/span[1]').text
        print("文本断言1，会员登陆:", dy1)
        time.sleep(3)
        # 用户名  密码

        self.driver.find_element(By.NAME, 'username').send_keys(casevalue1)
        time.sleep(3)
        self.driver.find_element(By.NAME, 'password').send_keys(casevalue2)
        time.sleep(8)
        # 登录按钮
        self.driver.find_element(By.XPATH, '//*[@id="theForm"]/div[5]/a').click()
        time.sleep(5)
        if caseyxj=="P1":
            # 断言2：断言文本：欢迎回来，13811033962
            dy2 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').text
            print("文本断言2，欢迎回来，13811033962:", dy2)
            time.sleep(2)
            # 断言3：断言文本：账户余额：¥ 988389770.25  中的 988389770.25
            dy3 = self.driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]').text
            dy31 = dy3.replace('¥ ', '')
            print("文本断言3，账户余额:", dy31)
            time.sleep(2)
            print()
        else:
            print("错误")
        logging.info('case.end')

if __name__ == '__main__':
    unittest.main()